package org.yangspring;

import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;

/**
 * Created by whyang on 2017/06/08.
 */

public class whyangSpringContext {
    private static ApplicationContext applicationContext;     //Spring应用上下文环境

    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringContextUtil.applicationContext = applicationContext;
    }

    /**
     * @return ApplicationContext
     */
    public static ApplicationContext getApplicationContext() {
        return applicationContext;
    }

    public static Object getBean(String name) throws BeansException {
        return applicationContext.getBean(name);
    }

}

/*
<bean id="SpringContextUtil " class="com.am.oa.commons.service.SpringContextUtil " singleton="true" />
*/

/*
ContextLoaderServlet ------ 这是2008年以前的老东西了。。。

class SpringContextLoaderServlet extends ContextLoaderServlet {

    whyangSpringContext whyangSC = new whyangSpringContext();

    private ContextLoader contextLoader;
    public void init() throws ServletException {
        this.contextLoader = createContextLoader();
        whyangSC.setApplicationContext(this.contextLoader.initWebApplicationContext(getServletContext()));
    }
}*/
